import SDKAdatper from "../core/SDKAdatper";

export default class WXSDK extends SDKAdatper {
    protected time: number = 0;
    protected _param: any;
    constructor(sdk: any, name: string) {
        super(sdk, name)
        if (this._sdk.onShow) {
            this._sdk.onShow(() => {
                this.backGame()
            })
        }

    }

    shareAppMessage(obj: any) {
        if (this._sdk.shareAppMessage) {
            this._param = obj;
            this._sdk.shareAppMessage(obj)
            this.time = Date.now()
        }
    }

    protected backGame() {
        if (this._param) {
            let disTime = Date.now() - this.time
            if (disTime >= 3000) {
                if (this._param.success) {
                    this._param.success()
                }
            } else {
                if (this._param.fail) {
                    this._param.fail()
                }
            }
            this._param = null;
        }

    }
}